/**
 * Copyright (c) 2015-2018, Michael Yang 杨福海 (fuhai999@gmail.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jboot.component.hystrix;

import com.netflix.hystrix.*;


public abstract class JbootHystrixCommand extends HystrixCommand<Object> {

    public JbootHystrixCommand(String key) {
        super(HystrixCommandGroupKey.Factory.asKey(key));
    }

    public JbootHystrixCommand(String key, int executionIsolationThreadTimeoutInMilliseconds) {
        //super(HystrixCommandGroupKey.Factory.asKey(key), executionIsolationThreadTimeoutInMilliseconds);
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(key))
                .andCommandKey(HystrixCommandKey.Factory.asKey(key))
                .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(key+"ThreadPool"))
                // 重写断路器基本策略属性
                                .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                                        .withExecutionTimeoutInMilliseconds(executionIsolationThreadTimeoutInMilliseconds)));
//                                        // 断路器是否开启，默认：true
//                                        .withCircuitBreakerEnabled(true)
//                                        // 统计时间滚动窗口，以毫秒为单位，默认：10秒
//                                        .withMetricsRollingStatisticalWindowInMilliseconds(10000)
//                                        // 断路器在整个统计时间内是否开启的阀值，也就是10秒钟内至少请求10次，断路器才发挥起作用
//                                        .withCircuitBreakerRequestVolumeThreshold(10)
//                                       // 断路器默认工作时间，默认:5秒，断路器中断请求5秒后会进入半打开状态，放部分流量过去重试
//                                        .withCircuitBreakerSleepWindowInMilliseconds(5000)
//                                       // 当出错率超过30%后断路器启动，默认:50%
//                                        .withCircuitBreakerErrorThresholdPercentage(30)
//                                        // 是否开启Hystrix超时机制，这里禁用Hystrix的超时，使用dubbo的超时
//                                        .withExecutionTimeoutEnabled(false))
//                        // 线程池配置，可考虑获取Dubbo提供者的线程数来配置断路器的线程数，若使用Hystrix的线程数则应大于Dubbo服务提供者的线程数，保证管道匹配
//                                .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(DEFAULT_THREADPOOL_CORE_SIZE)));
    }

    public JbootHystrixCommand(HystrixCommandGroupKey group) {
        super(group);
    }

    public JbootHystrixCommand(HystrixCommandGroupKey group, HystrixThreadPoolKey threadPool) {
        super(group, threadPool);
    }

    public JbootHystrixCommand(HystrixCommandGroupKey group, int executionIsolationThreadTimeoutInMilliseconds) {
        super(group, executionIsolationThreadTimeoutInMilliseconds);
    }

    public JbootHystrixCommand(HystrixCommandGroupKey group, HystrixThreadPoolKey threadPool, int executionIsolationThreadTimeoutInMilliseconds) {
        super(group, threadPool, executionIsolationThreadTimeoutInMilliseconds);
    }

    public JbootHystrixCommand(Setter setter) {
        super(setter);
    }

}

